home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / batchut / printenv.zip / PRINTENV.C < prev    next >
Text File  |  1989-05-07  |  1KB  |  43 lines

  1. /*
  2.  * printenv - print the "values" of shell variables, sort of like
  3.  *            in Unix.  This one accepts multiple arguments, though.
  4.  */
  5. #include <stdio.h>
  6. #include <stdlib.h>
  7. #include <string.h>
  8.  
  9. char copyright[] = "89.05.07 version (C) Copyright 1989 RAMontante";
  10. /* Permission granted to use or redistribute this program in source
  11.  * or executable form, for noncommercial purposes, as long as this
  12.  * copyright notice remains intact.
  13.  */
  14.  
  15. int return_val = 0;
  16.  
  17. void main(int argc, char *argv[], char *env[])
  18. {
  19.     char **envp, **argp;
  20.     char *val;
  21.     int no_match;
  22.  
  23.     if (argc < 2) {
  24.         for (envp = env; *envp != NULL; ) {
  25.             puts(*(envp++));
  26.         }
  27.     } else for (argp = argv; *(++argp) != NULL; ) {
  28.         argc = strlen(*argp);    /** Let's be cheap and reuse `argc' **/
  29.         envp = env;
  30.         while (*envp != NULL) {
  31.             if (0 == (no_match = strnicmp(*envp++, *argp, argc))) {
  32.                 for (val = *(--envp) + argc; *(val++) != '='; )
  33.                     {}
  34.                 puts(val);
  35.                 break;
  36.             }
  37.         }
  38.         if (no_match)
  39.             return_val++;
  40.     }
  41.     exit(return_val);
  42. }
  43.